import java.util.Arrays;

public class Test {
    public static void func1(int[] array1) {
        array1 = new int[]{7, 8, 9};
    }

    public static void func2(int[] array2) {
        array2[0] = 6;
    }

    public static int[] myToString(int[] array) {
        //拷贝数组
        int[] arrcop = new int[array.length];
        for (int i = 0; i < array.length; i++) {
            arrcop[i] = array[i];
        }
        return arrcop;
    }
    //求平均 *1.0 返回小数

    //二分查有序数组key
    public static int find(int[] array, int key) {
        int letf = 0;
        int right = array.length - 1;
        while (letf <= right) {
            int mid = (letf + right) / 2;
            if(array[mid] == key){
                return mid;
            }else if(array[mid]>key){
                right = mid-1;
            }else {
                letf = mid+1;
            }
        }
        return -1;
    }

    public static void main(String[] args) {
//        int[] array = {1,2,3};
//        func1(array);
//        for (int i = 0; i < array.length; i++) {
//            System.out.print(array[i]+" ");
//        }
//        System.out.println();
//        System.out.println("==============");
//        func2(array);
//        for (int x:array) {
//            System.out.print(x+" ");
//        }
//        System.out.println();
//        System.out.println("=============");
//        String ret = Arrays.toString(array);    //讲数组以字符串形式返回 加[]
//        System.out.println(ret);

        int[] array1 = new int[]{1, 2, 3, 4};
        int[] array2 = new int[]{3, 4, 5, 6};
        int[] copy = new int[array1.length];
        copy = array1.clone();  //clone():产生对象的一个副本
        /*
         * 1、是你要拷贝的数组
         * 2、你要从这个数组的哪个下标开始拷贝
         * 3、你要拷贝到哪个数组
         * 4、你要拷贝到这个数组的哪个位置开始
         * 5、你要拷贝多大
         */

        System.arraycopy(array1, 0, copy, 0, array1.length);
        System.out.println(copy);
        System.out.println(Arrays.toString(array1));
        System.out.println("=====================");
        System.out.println(copy);
        System.out.println(Arrays.toString(copy));
        System.out.println("===============");
        System.out.println(find(array1,4));

    }

}
